//
//  UIBarButtonItem+Extension.swift
//  Weibo
//
//  Created by Albert Zhu on 16/9/28.
//  Copyright © 2016年 Albert Zhu. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    /// 创建UIBarButtonItem
    ///
    /// - parameter title:    标题
    /// - parameter fontSize: 字号
    /// - parameter isBack: 是否带有箭头
    ///
    /// - returns:
    convenience init(title: String, fontSize: CGFloat = 16, target: AnyObject?, action: Selector, isBack: Bool = true) {
        
        let btn = UIButton.az_textButton(text: title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange, backgroundImage: nil)
        if isBack {
            let imageName = "navigationbar_back_withtext"
            
            btn.setImage(UIImage(named: imageName), for: .normal)
            btn.setImage(UIImage(named: imageName + "_highlighted"), for: .highlighted)
            btn.sizeToFit()
        }
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        self.init(customView: btn)
    }
}
